var app = getApp()
const APP_BASE_URL = app.serverUrl;
 
function header1(){
   var userInfo = app.getGlobaluserInfo()
   var  Header1 = {
      'content-type': 'application/json',
      'userId': userInfo.id,
      'userToken': userInfo.userToken
   };
   return Header1;
}
function header2(){
   var userInfo = app.getGlobaluserInfo()
   var  Header2 = {
      'content-type': 'application/x-www-form-urlencoded',
      'userId': userInfo.id,
      'userToken': userInfo.userToken
   };
   return Header2;
}

const postRequest = (url, data, header) => {
   let _url = APP_BASE_URL + url;
   return new Promise(
      (resolve, reject) => {
         wx.request({
            url: _url,
            method: 'POST',
            data: data,
            header: header,
            success(res) {
               if (res.data.status == 200) {
                  resolve(res.data.data)
               } else {
                  wx.showToast({
                     title: res.data.msg,
                     icon: "none",
                     duration: 3000
                  })
               }

            },
            fail(error) {
               reject(error)
            }
         })
      }


   );
}

module.exports = {
   //用户登录 
   login: (data) => {
      return postRequest('/login', data, header1())
   },
   //用户注册 
   regist: (data) => {
      return postRequest('/regist', data, header1())
   },
    ///user/query 查询用户信息 
    userQuery: (data) => {
      return postRequest('/user/query', data, header2())
   },
   //注销登录  logout
   logout: (data) => {
      return postRequest('/logout', data, header2())
   },
   //首页视频列表  
   videos: (data, pageNum, pageSize, isSaveRecord) => {
      return postRequest('/video/list?pageNum=' + pageNum + "&pageSize=" + pageSize + "&isSaveRecord=" + isSaveRecord, data, header1())
   },
   //查看当前视频是否被点赞过 
   isLikeVideo: (data) => {
      return postRequest('/videos/isLikeVideo', data, header2())
   },
   //点赞或者是取消点赞 
   like: (data) => {
      return postRequest('/videos/like', data, header2())
   },
   //网络请求热搜  视频的热搜词   /video/recordslist
   recordslist: (data) => {
      return postRequest('/video/recordslist', data, header1())
   },
   //背景音乐 列表 /bgm/list
   bgmList: (data) => {
      return postRequest('/bgm/list', data, header1())
   },






}